package tech.yunland.shop.domain.service;

import com.moyuer.bsf.domain.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tech.yunland.shop.domain.dao.LessonsDao;
import tech.yunland.shop.domain.dao.UserLessonsDao;
import tech.yunland.shop.domain.model.UserLessons;

import java.util.List;

/**
 * Created by v on 17-7-3.
 */
@Service
public class UserLessonsServiceImpl implements UserLessonsService {

    @Autowired
    private UserLessonsDao userLessonsDao;

    @Autowired
    private UserDao userDao;

    @Autowired
    private LessonsDao lessonsDao;

    @Override
    public void choice(String uid, List<String> lids) {
        if (lids != null && lids.size() > 0) {
            for (String lid : lids) {
                UserLessons userLessons = new UserLessons();
                userLessons.setStudents(userDao.get(uid));
                userLessons.setLessons(lessonsDao.get(lid));
                userLessonsDao.saveOrUpdate(userLessons);
            }
        } else {
            throw new RuntimeException("请选择课程");
        }
    }
}
